package com.tianyu.jty.shop.web;

import com.tianyu.jty.common.persistence.Page;
import com.tianyu.jty.common.persistence.PropertyFilter;
import com.tianyu.jty.common.web.BaseController;
import com.tianyu.jty.shop.entity.Goods;
import com.tianyu.jty.shop.service.GoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import java.util.List;
import java.util.Map;

/**
 * 商品controller
 *
 * @author ty
 * @date 2015年1月22日
 */
@Controller
@RequestMapping("shop/goodsListPopup")
public class GoodsPopupController extends BaseController {

  @Autowired
  private GoodsService goodsService;

  /**
   * 默认页面
   */
  @RequestMapping(method = RequestMethod.GET)
  public String list() {
    return "shop/goodsListPopup";
  }

  /**
   * 获取商品json
   */
  @RequestMapping(value = "json", method = RequestMethod.GET)
  @ResponseBody
  public Map<String, Object> goodsList(HttpServletRequest request) {
    Page<Goods> page = getPage(request);
    List<PropertyFilter> filters = PropertyFilter.buildFromHttpRequest(request);
    page = goodsService.search(page, filters);
    return getEasyUIData(page);
  }

}
